#include<stdio.h>
#include<conio.h>

struct fieldinfo                               /* STRUCTURE DECLARATION  */
{
     char * fieldname;
     int size;
};
struct tableinfo
{
     char * tablename;
     int no_of_fields;
     struct fieldinfo  fields[20];
}table;

int atoi(int n,char s[])                     /* A TO I FUNC. FOR FIELD SIZE  */
{
int i,j=ans=0;
for(i=n-1;i>=0;i--,j++)
ans=ans+(s[i]-'0')*(10^j);
return(ans);
}

store_table_info(struct tableinfo table)       /* FUNC. FOR FILE STORAGE  */
{
FILE *fp,*fs;
fp=fopen(table.tablename,"a+");
fs=fopen("systables.dat","a+");
fprintf(fs,"%-20s\t%d\n",table.tablename,table.no_of_fields);
for(int i=0;i<table.no_of_fields;i++)
{
fprintf(fs,"%-20s\t%d\n",table.field[i].fieldname,table.field[i].size);
fprintf(fp,"%-20s\t",table.field[i].fieldname);
}
fclose(fs);
fclose(fp);
}


void main()
{
char *input,*temp,temp_fieldname[20],temp_size[10];
gets(input);
while(*input!=' ')
*temp++=*input++;
*temp='\0';
table.tablename=temp;
table.no_of_fields=*++input;
for(int i=j=k=0;i<table.no_of_fields;i++)              /* LOOP FOR FIELD INFO */
{
while(*++input!=',')
temp_fieldname[j++]=*input;
temp_fieldname[j]='\0';
table.field[i].fieldname=temp_fieldname;
while(*++input!=';')
temp_size[k++]=*input;
temp_size[k]='\0';
table.field[i].size=atoi(k,temp_size);
j=k=0;
}
store_table_info(table);
}



